﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emergency4.Dal;
using Emergency4.From;
using Emergency4.Session;

namespace Emergency4.From
{
    public partial class EmergencyMaintenanceRequest : Form
    {
        public EmergencyMaintenanceRequest()
        {
            InitializeComponent();
        }

        //资产id，即assetId;
        public int id;
        private void button1_Click(object sender, EventArgs e)
        {
            if(priorityName.Text == "" || priorityName.Text == null)
            {
                MessageBox.Show("priority不能为空!");
                return;
            }
            if (descriptionText.Text == "" || descriptionText.Text == null)
            {
                MessageBox.Show("descriptionText不能为空!");
                return;
            }
            if (otherConsideration.Text == "" || otherConsideration.Text == null)
            {
                MessageBox.Show("otherConsideration不能为空!");
                return;
            }

            EmergencyMaintenance em = new EmergencyMaintenance();
            em.AssetID = id;
            em.PriorityID = AssetDal.findByPriorityName(priorityName.Text);
            em.DescriptionEmergency = descriptionText.Text;
            em.OtherConsiderations = otherConsideration.Text;
            em.EMEndDate = DateTime.Now.Date;
            AssetDal.AddEMergency(em);
            //提交成功，显示相应的信息
            MessageBox.Show("OK");
            //关闭当前窗口
            this.Close();
        }

        //
        private void EmergencyMaintenanceRequest_Load(object sender, EventArgs e)
        {
            Asset asset = AssetDal.findByAssetId(id);
            if (asset != null)
            {
                assetSN.Text = asset.AssetSN;
                assetName.Text = asset.AssetName;
                departmentName.Text = asset.DepartmentLocation.Department.Name;

            }
            priorityName.Items.Clear();
            List<Priority> priority = AssetDal.findByAllPriority();
           
            foreach(Priority item in priority)
            {
                priorityName.Items.Add(item.Name);
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
